{% layout = 'dashboard/layout_dashboard.html' %}

<!-- 任务菜单 -->
<div class="menublock border-right">

    <!-- 任务概览 -->
    <div class="container-fluid pt-2 px-2 pb-0">
        <i class="fa fa-list mr-2"></i><label class="title">我的任务</label>
        <div class="btn-link pull-right" onclick="return create_task();">
            <i class="fa fa-plus mr-1"></i>发布任务
        </div>
    </div>
    <hr class="m-0">
    <div class="p-4 mx-2" style="color:rgb(102, 102, 102); font-size: .75em;">
        <div class="row border-bottom">
            <div class="col-6 text-center border-right p-2">
                <h2>{{summary.created}}</h2>
                <i class="fa fa-circle-o mr-1"></i>待办中
            </div>
            <div class="col-6 text-center p-2">
                <h2>{{summary.underway}}</h2>
                <i class="fa fa-dot-circle-o mr-1"></i>开发中
            </div>
        </div>

        <div class="row">
            <div class="col-6 text-center border-right p-2">
                <h2>{{summary.testing}}</h2>
                <i class="fa fa-exclamation-circle mr-1"></i>测试中
            </div>
            <div class="col-6 text-center p-2">
                <h2>{{summary.finished}}</h2>
                <i class="fa fa-check-circle mr-1"></i>已完成
            </div>
        </div>
    </div>
    <ul class="flex-column px-4">
        <li class="d-flex justify-content-between align-items-center">
            <a id="task-menu-default" class="menu-link active" href="#" onclick="return filter_task(this, '/dashboard/tasks/all_of_mine');"><i class="fa fa-list-alt mr-2"></i>我参与的任务</a>
            <span class="badge badge-secondary">{{summary.created + summary.underway + summary.testing + summary.finished}}</span>
        </li>
        <li class="d-flex justify-content-between align-items-center">
            <a class="menu-link" href="#" onclick="return filter_task(this, '/dashboard/tasks/assigned_to_me');"><i class="fa fa-hand-o-right mr-2"></i>指派给我的任务</a>
            <span class="badge badge-secondary">{{mine.assigned_to_me}}</span>
        </li>
        <li class="d-flex justify-content-between align-items-center">
            <a class="menu-link" href="#" onclick="return filter_task(this, '/dashboard/tasks/create_by_me');"><i class="fa fa-bullhorn mr-2"></i>我发布的任务</a>
            <span class="badge badge-secondary">{{mine.create_by_me}}</span>
        </li>
    </ul>

    <!-- 按优先级筛选功能 -->
    <div class="container-fluid mt-2 p-0">
        <i class="fa fa-sort mx-2"></i> <label class="title">按优先级筛选</label>
    </div>
    <hr class="m-0">
    <ul class="flex-column px-4 mt-2">
        {% for idx, info in ipairs(weights or {}) do %}
        <li class="d-flex justify-content-between align-items-center">
            <a class="menu-link" href="#" onclick="return filter_task(this, '/dashboard/tasks/filter_weight', '{{idx}}');"><i class="fa fa-circle {{info.color}} mr-2"></i>{{info.title}}</a>
            <span class="badge badge-secondary">{{mine.weights[idx] or 0}}</span>
        </li>
        {% end %}
    </ul>

    <!-- 按项目筛选功能 -->
    <div class="container-fluid mt-3 p-0">
        <i class="fa fa-filter mx-2"></i><label class="title">按项目筛选</label>
    </div>
    <hr class="m-0">
    <ul class="flex-column px-4 mt-2">
        {% for id, info in pairs(mine.projects) do %}
        <li class="d-flex justify-content-between align-items-center">
            <a class="menu-link" href="#" onclick="return filter_task(this, '/dashboard/tasks/filter_proj', '{{id}}', '{{info.name}}');"><i class="fa fa-bookmark mr-2"></i>{{info.name}}</span></a>
            <span class="badge badge-secondary">{{info.count}}</span>
        </li>
        {% end %}
    </ul>
</div>

<!-- 任务面板 -->
<div id="task-content" class="contentblock">
    {["dashboard/tasks/view_tasks.html"]}
</div>

<script>
function create_task() {
    $.post('/dashboard/tasks/try_create', {}, function(ret) {
        $('#task-content').empty();
        $('#task-content').append($(ret));
    }, 'html');
}

var last_filter_menu = $('#task-menu-default');
function filter_task(menu, url, p1, p2) {
    if (last_filter_menu) last_filter_menu.removeClass('active');
    last_filter_menu = $(menu);
    last_filter_menu.addClass('active');

    $('#task-content').empty();
    $('#task-content').get(0).innerHTML = '<div class="text-center text-muted" style="margin-top: 40%"><i class="fa fa-spinner fa-spin fa-3x fa-fw"></i></div>';

    $.post(url, { p1: p1, p2: p2 }, function(ret) {
        $('#task-content').empty();
        $('#task-content').append($(ret));
    }, 'html');
}
</script>